﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TitipNyobaYan.Views
{
    public partial class ViewOrang : Form
    {
        Controllers.Control<Models.ORANG> conOrang;
        public ViewOrang()
        {
            InitializeComponent();
            conOrang = new Controllers.Control<Models.ORANG>();
            daftarOrang.DataSource = conOrang.view();
        }
        public void tambah(object sender, EventArgs e)
        {
            var orang = new Models.ORANG
            {
                ID_ORANG = txtID_Orang.Text,
                NAMA_ORANG = txtNama.Text,
                ALAMAT_ORANG = txtAlamat.Text,
                TELEPON_ORANG = txtTelepon.Text,
                HAK_AKSES_ORANG = true,
                PASS_ORANG = txtPass.Text
            };
            conOrang.tambah(orang);
            daftarOrang.DataSource = conOrang.view();
        }
        public void hapusBut(object sender, EventArgs e)
        {
            conOrang.hapus(txtID_Orang.Text);
            daftarOrang.DataSource = conOrang.view();
        }

        public void editBut(object sender, EventArgs e)
        {
            var orang = new Models.ORANG
            {
                ID_ORANG = txtID_Orang.Text,
                ALAMAT_ORANG = txtAlamat.Text,
                NAMA_ORANG = txtNama.Text,
                TELEPON_ORANG = txtTelepon.Text,
                PASS_ORANG = txtPass.Text,
                STATUS_ORANG = true,
                HAK_AKSES_ORANG = true
            };
            conOrang.edit(orang);
            daftarOrang.DataSource = conOrang.view();
        }

        private void daftarOrang_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                var orang = conOrang.get(daftarOrang.SelectedRows[0].Cells[0].Value.ToString());
                txtID_Orang.Text = orang.ID_ORANG;
                txtNama.Text = orang.NAMA_ORANG;
                txtAlamat.Text = orang.ALAMAT_ORANG;
                txtTelepon.Text = orang.TELEPON_ORANG;
                txtStatus.Text = orang.STATUS_ORANG.ToString();
                txtHak.Text = orang.HAK_AKSES_ORANG.ToString();
                txtPass.Text = orang.PASS_ORANG;
            }
            catch { }
        }
    }
}
